﻿Imports System.Data

Partial Class WebForm_ManageBanner_SearchBanner
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

        End If

    End Sub

    'Delegate-GridView1SelectedIndexChanged
    Public Event GridView1SelectedIndexChanged(ByVal source As Object, ByVal e As System.EventArgs)

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        RaiseEvent GridView1SelectedIndexChanged(sender, e)
    End Sub

    Protected Sub ddlActive_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddlActive As DropDownList = sender

        If ddlActive.Items.Count = 0 Then

            For Each DR As DataRow In MyObj.GetCodeMappingData("Banner", "Active").Rows
                ddlActive.Items.Add(New ListItem(DR.Item("Text"), DR.Item("Value")))
            Next

        End If
    End Sub

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim BannerID As String = GridView1.DataKeys(e.Row.RowIndex)("BannerID").ToString()
            Dim clsDB As New MyclsDBUtility
            Dim dt As Data.DataTable = clsDB.Banner_SelectByBannerID(BannerID)
            If dt.Rows.Count > 0 Then
                Dim newUrl As String
                Dim imgbtnBanner As ImageButton = TryCast(e.Row.FindControl("imgbtnBanner"), ImageButton)
                If System.IO.File.Exists(Server.MapPath(dt.Rows(0)("theFileName").ToString())) Then
                    imgbtnBanner.Visible = True
                    imgbtnBanner.ImageUrl = dt.Rows(0)("theFileName").ToString()
                    newUrl = TryCast(e.Row.FindControl("lblUrl"), Label).Text.Replace("http://", "")
                    If newUrl <> "" Then newUrl = "http://" & newUrl
                    imgbtnBanner.OnClientClick = "window.open('" & newUrl & "');return false;"
                Else
                    'imgbtnBanner.Visible = False
                End If
                Dim ddlActive As DropDownList = TryCast(e.Row.FindControl("ddlActive"), DropDownList)
                MyObj.MatchItem(ddlActive, GridView1.DataKeys(e.Row.RowIndex)("Active").ToString())
            End If

        End If
    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim BannerID As String = GridView1.DataKeys(e.RowIndex)("BannerID").ToString()
        Dim clsDB As New MyclsDBUtility
        Dim dt As Data.DataTable = clsDB.Banner_SelectByBannerID(BannerID)
        If dt.Rows.Count > 0 Then
            Dim imgbtnBanner As ImageButton = TryCast(GridView1.Rows(e.RowIndex).FindControl("imgbtnBanner"), ImageButton)
            If System.IO.File.Exists(Server.MapPath(dt.Rows(0)("theFileName").ToString())) Then
                System.IO.File.Delete(Server.MapPath(dt.Rows(0)("theFileName").ToString()))
            End If
        End If


    End Sub
End Class


Partial Class WebForm_ManageBanner_SearchBanner

    Public Sub GridView1DataBind()
        GridView1.DataBind()
    End Sub

    Public ReadOnly Property GridView1SelectedValue() As Integer

        Get
            Return IIf(GridView1.SelectedValue Is Nothing, 0, GridView1.SelectedValue)
        End Get

    End Property

End Class